package code.starivan.leetcode;

/**
 * Created by Ivan on 2015/8/22.
 */

/*Given a sorted linked list, delete all duplicates such that each element appear only once.

        For example,
        Given 1->1->2, return 1->2.
        Given 1->1->2->3->3, return 1->2->3.*/



public class N083_RemoveDuplicates {
    //Definition for singly-linked list.
    class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
        }
    }

    public ListNode deleteDuplicates(ListNode head) {
        if(head==null)
            return head;

        ListNode node=head.next;
        ListNode nodePre=head;

        while (node!=null){
           if(node.val==nodePre.val){
               nodePre.next=node.next;
           }else{
                nodePre=node;
            }

            node=node.next;
        }

        return head;
    }
}
